<!DOCTYPE html>
<html lang="zh-CN"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Cache-Control"  content="no-transform">
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>订单支付</title>
    <link href="/statics/view/css/yy_common.css" rel="stylesheet">
    <link href="/statics/view/css/yy_pay.css" rel="stylesheet">
    <script src="/statics/jquery/jquery.min.js"></script>
    <script src="/statics/layer.m/layer.m.js"></script>
    <script src="/statics/view/js/db.js"></script>
<body>
<div class="m-pay-order">
    <div data-pro="list">
        <div id="pro-view-1">
            <div data-pro="entry" class="m-pay-order-list">
                <div class="m-pay-order-list-item" id="pro-view-2"><span class="m-pay-order-list-item-name">${dbProduct.name}</span>
                    <span class="m-pay-order-list-item-num"><b class="txt-red">${num}</b>人次</span>
                </div>
            </div>
            <div class="m-pay-order-total">商品合计：<b class="txt-red">${dbTimes.singleAmount*num}宝币</b></div>
        </div>
    </div>
    <div data-pro="options" class="m-pay-order-options">
        <div class="w-option w-option-unfold" id="pro-view-6">
            <div class="w-bar" data-pro="groupTitle">
                <span id="pro-view-24">其他支付方式<span class="txt-red w-bar-extText">${dbTimes.singleAmount*num}元</span></span>
            </div>
        [#if dbTimes.singleAmount==0]
            <div class="w-bar-content" data-pro="groupItems">
                <span class="pro-radioGroup">
                    <div class="w-radioBar w-bar w-radioBar-checked">
                        <b class="w-radio"></b>账户余额:（${member.virtualCurrency}宝币）
                        <div class="w-bar-ext">
                            <input name="paymentMethod" checked="checked" value="localVirtualPayPlugin" type="radio">
                        </div>
                    </div>
                </span>
            </div>
            <div class="w-bar-content" style="padding: 8px;">
                <p>话费购是中国联通提供的基于通信账户的付费工具，致力于为用户提供“安全、便捷、高效”的全新互联网消费体验</p>
            </div>
            [#else]
                <div class="w-bar-content" data-pro="groupItems">
                <span class="pro-radioGroup">
                    <div class="w-radioBar w-bar">
                        <b class="w-radio"></b>账户余额:（${member.virtualCurrency}宝币）
                        <div class="w-bar-ext">
                            <input name="paymentMethod" value="localVirtualPayPlugin" type="radio">
                        </div>
                    </div>
                </span>
                </div>
                <div class="w-bar-content" data-pro="groupItems">
                <span class="pro-radioGroup">
                    <div class="w-radioBar w-bar w-radioBar-checked" id="pro-view-9">
                        <b class="w-radio"></b>话费购
                        <div class="w-bar-ext">
                            <input name="paymentMethod" checked="checked" value="wo3DirectPlugin" type="radio">
                        </div>
                    </div>
                </span>
                </div>
                <div class="w-bar-content" style="padding: 8px;">
                    <p>话费购是中国联通提供的基于通信账户的付费工具，致力于为用户提供“安全、便捷、高效”的全新互联网消费体验</p>
                </div>
        [/#if]

        </div>
    </div>
    <div data-pro="submit" class="m-pay-order-submit"><button class="w-button w-button-main w-button-l" id="payBtn" data-id="">确认支付</button></div>
</div>
<form id="doaiAppPayFrom"  action="" method="post"></form>
<script type="text/javascript">

    $(function(){
        [#if dbTimes.singleAmount==0]
             var lastChoice="localVirtualPayPlugin";
             $("#payBtn").attr("data-id","localVirtualPayPlugin");
        [#else]
             var lastChoice="wo3DirectPlugin";
              $("#payBtn").attr("data-id","wo3DirectPlugin");
        [/#if]

        $(".w-radioBar").click(function(){
            var $this=$(this);
            $(".w-radioBar").removeClass("w-radioBar-checked");
            $("input[name='paymentMethod']").attr("checked",false);
            $this.addClass("w-radioBar-checked");
            $this.find("input[name='paymentMethod']").attr("checked",true);
            lastChoice=$this.find("input[name='paymentMethod']").val();
            $("#payBtn").attr("data-id",lastChoice);
        });
        $("#payBtn").click(function(){
            var pluginId=$(this).attr("data-id");
            layer.open({
                type: 2,
                content: '正在提交订单~'
            });
            $.ajax({
                url: "/db/pay/create",
                type:'POST',
                data:{
                    productId:"${dbProduct.id}",
                    timesNo:"${dbTimes.timesNo}",
                    num:"${num}",
                    paymentPluginId:pluginId
                },
                dataType:'json',
                success: function (data){
                    if(data.type=='success'){
                        paySubmit(data.order.id,pluginId);
                    }else{
                        layer.closeAll();
                        if(data.url!=null){
                            layer.open({
                                title: '提示',
                                content: data.content,
                                btn: ['确定', '取消'],
                                yes: function(index){
                                    location.href = data.url;
                                }
                            });
                        }else{
                            layer.open({
                                content: data.content,
                                style: 'background-color:#09C1FF; color:#fff; border:none;',
                                time: 2
                            });
                        }
                    }
                },error:function(){
                    layer.closeAll();
                    layer.open({
                        content:"服务器异常,请稍后再试!",
                        time: 2
                    });
                }
            });
        });
    });

    function paySubmit(orderId,pluginId){
        $.ajax({
            url: "/db/pay/submit?orderId="+orderId+"&paymentPluginId="+pluginId,
            type:'POST',
            dataType:'json',
            success: function (data){
                if(data.type=="success"){
                    $("#doaiAppPayFrom").attr("action",data.requestUrl);
                    $("#doaiAppPayFrom").attr("method",data.requestMethod);
                    if(data.parameterMap!=null){
                        for (var key in data.parameterMap) {
                            var str="<input type='hidden' name='"+key+"' value='"+data.parameterMap[key]+"'/>";
                            $(str).appendTo("#doaiAppPayFrom")
                        }
                    }
                    $("#doaiAppPayFrom").submit();
                }else{
                    layer.closeAll();
                    layer.open({
                        content: data.content,
                        style: 'background-color:#09C1FF; color:#fff; border:none;',
                        time: 2
                    });
                }
            }
        });
    }
</script>
<div class="cnzz" style="display: none;">
    <script src="http://s4.cnzz.com/z_stat.php?id=1256836410&web_id=1256836410" language="JavaScript"></script>
</div>
</body>
</html>